#include "admin.h"
#include "judge.h"
#include "academy_admin_func.h"
#include "athlete_func.h"
#include <stdio.h>

//ycna
#pragma once

//总管理员
void admin_query_single_collge(){
    printf("请输入院系编码：");
        char collge_code[20];
        scanf("%s",collge_code);
        // printf("colle_code:%s\n",collge_code);
        queryCollege(collge_code);
}
void admin_query_collge(){
    //
    printf("1.查询所有院系信息，2.查询单个院系信息，3.退出：");
    int choice;
    scanf("%d",&choice);
    switch (choice) {
        case 1:
        printAllColleges();
        break;
        case 2:
        admin_query_single_collge();
        break;
        case 3:
        return;
    }
}//
void admin_add_academy(){
    College new_collge;
        printf("请输入院系代码：");
        scanf("%s",new_collge.code);
        printf("请输入院系名字：");
        scanf("%s",new_collge.name);
        addCollege(new_collge);
}
void admin_delete_academy(){
     printf("请输入要删除的院系编码：");
         char collge_code[20];
        scanf("%s",collge_code);
        deleteCollege(collge_code);
}
void admin_modify_academy(){

    College new_collge;
        printf("请输入院系代码：");
        scanf("%s",new_collge.code);
        printf("请输入院系名字：");
        scanf("%s",new_collge.name);
        modifyCollege(new_collge);
}
void admin_manage_academy(){    
    printf("1.查询院系信息，2.添加院系信息，3.删除院系信息，4.修改院系信息，5.退出：");
    int choice;
    scanf("%d",&choice);
    switch (choice) {
        case 1:
        admin_query_collge();
        break;
        case 2: 
        admin_add_academy();
        break;
        case 3:
        admin_delete_academy();
        break;
        case 4:
        admin_modify_academy();
        break;
        case 5:
        return;
    }
}//
void admin_query_single_game(){
    printf("请输入项目编号：");
    int code;
    scanf("%d",&code);
    queryGame(code);
}//
void admin_query_games(){
    printf("1.查询所有比赛，2。查询单个比赛，3.退出\n");
    int choice=0;
    scanf("%d",&choice);
    switch (choice) {
        case 1:
        printAllGame();
        break;
        case 2:  
        admin_query_single_game();
        break;
        case 3:
        return;
    }
}//
void admin_add_game(){
    Game game;
    printf("请输入比赛名称：");
    scanf("%s",game.name);
    printf("请输入比赛编码：");
    scanf("%d",&game.code);
    printf("请输入比赛组别");
    scanf("%s",game.type);
    printf("请输入运动员数量");
    scanf("%d",&game.num);
    printf("请输入比赛性质");
    scanf("%s",game.group);
    creatGame(game);
}//
void admin_delete_game(){
    printf("请输入比赛编号：");
    int code;
    scanf("%d",&code);
    deleteGame(code);
}//
void admin_modify_game(){
    Game game;
    printf("请输入比赛编码：");
    scanf("%d",&game.code);
    if(isGameExist(game.code)==0)printf("项目不存在！");
    printf("请输入比赛名称：");
    scanf("%s",game.name);
    printf("请输入比赛性质：");
    scanf("%s",game.type);
    printf("请输入运动员数量：");
    scanf("%d",&game.num);
    printf("请输入比赛组别：");
    scanf("%s",game.group);
    modifyGame(game);
}//
void admin_manage_games(){
    int choice=0;
    while (1) {
        printf("1.查询比赛项目，2.增加比赛项目，3.删除比赛项目，4.修改比赛项目，5.退出\n");
        scanf("%d",&choice);
        switch (choice) {
            case 1:
            admin_query_games();
            break;
            case 2:
            admin_add_game();
            break;
            case 3:
            admin_delete_game();
            break;
            case 4:
            admin_modify_game();
            break;
            case 5:
            return;
        }
    }
    

}//
void admin_search(){
    printf("1.查看运动员比赛信息，2.查看运动员排名信息,3.退出：");
    char code[20];
    int choice;
    scanf("%d",&choice);
    printf("\n");
    switch (choice) {
        case 1:
        //athlete.txt
        printf("请输入运动员编号：");
        scanf("%s",code);
        printf("code:%s",code);
        query_my_match(code);
        printf("查询结束");
        break;
        case 2:
        printf("请输入运动员编号：");
        scanf("%s",code);
        query_my_rank(code);
        break;
        case 3:
        return;
    }
    
    
}//
void admin_appeal(){

    printf("1.审核，2.修改,3.退出:");
    int choice;
    scanf("%d",&choice);
    switch (choice) {
        case 1:
        adminReview();//time
        break;
        case 2:
        adminChange();//athlete 状态码2->6
        break;
        case 3:
        return;
    }
}//


void admin_menu(){
    int choic=0;
    while (1) {
        printf("1.管理院系信息，2.管理项目信息，3.查询运动员信息，4.处理申诉，9.退出\n");
        scanf("%d",&choic);
        switch (choic) {
            case 1:
                admin_manage_academy();
                break;
            case 2:
                admin_manage_games();//完成
                break;
            case 3:
                admin_search();
                break;
            case 4:
                admin_appeal();
                break;
            case 9:
                return;
        }
    }
  
}//





//学院管理员

void academy_search_all_score_and_rank(){
    calculateCollegeScores();
}
void academy_search_single_score_and_rank(char *academy_code){
    getPlayersScores(academy_code);
}
void academy_search_athleth_info(){
    // printf("你正在academy_search_athleth_info\n");
    printf("输入要查询的学生编号：");
    char code[20];
    scanf("%s",code);
    
    query_my_match(code);
}
void academy_search_game_score(char*academy_code){
    getGamesScore(academy_code);
}

void academy_appeal(char *code){
    printf("1.审核运动员申诉，2.提交已审核的申诉，3.退出:");
    int choice;
    scanf("%d",&choice);
    printf("\n");
    switch (choice) {
        case 1 :    
            academyReview();
            break;
        case 2:
            academyComplaint(code);
            break;
        case 3:
            return;
    }
   
}

void academy_admin_menu(char*academy_code){
     int choic=0;
    while (1) {
        printf("1.查询本院总分数以及总排名，2.查询本院各项得分，3.查找本院运动员得分与其他信息，4.处理运动员申诉，5.退出\n");
        scanf("%d",&choic);
        switch (choic) {
            case 1:
                academy_search_all_score_and_rank(academy_code);//未完成
                break;
            case 2:
                academy_search_single_score_and_rank(academy_code);//已完成
                break;
            case 3:
                academy_search_athleth_info();//已完成
                break;
            case 4:
                academy_appeal(academy_code);//处理申诉
                break;
            case 6:
                return;
        }
    }
  
}







//裁判员

//已完成
void referee_input_game_info() {
   
        // 调用输入成绩的函数
    inputResult_referee();
}



void referee_appeal(){
     judgeReview();
}//完成

void referee_menu(){
     int choic=0;
    while (1) {
        printf("1.录入成绩与名次，2.审核申诉，3.退出\n");
        scanf("%d",&choic);
        switch (choic) {
            case 1:
                referee_input_game_info();
                break;
            case 2:
                referee_appeal();
                break;
            case 3:
                return;
        }
    }
}//完成







//运动员

void athlete_search(char* code){
    printf("1.查看自己的比赛排名，2.查看自己的报名信息，3.退出：");
    int choice;
    scanf("%d",&choice);
    switch (choice) {
        case 1:
        query_my_rank(code);
        break;
        case 2:
        query_my_match(code);
        break;
        case 3:
        return;
    }
}
void athlete_search_games(char* code){
    printf("请输入要查看的比赛编码：");
    int game_code;
    scanf("%d",&game_code);
    sort_athletes_by_score(game_code);
}
void athlete_appeal(char* code){
    athleteQuestioning(code);
}

void athlete_menu(char *code){
    //已完成
     int choic=0;
    while (1) {
        printf("1.查看本人分数以及名次，2.查看各项目排名，3.申诉，4.退出\n");
        scanf("%d",&choic);
        switch (choic) {
            case 1:
                athlete_search(code);
                break;
            case 2:
                athlete_search_games(code);
                break;
            case 3:
                athlete_appeal(code);
                break;
            case 4:
                return;
        }
    }
}